// Per Frag ADS Lighting model (Phong shading) - based on: 
//    RealTime Rendering class notes (Celes, W. 2014) 
//    Mathematics for 3D Game Programming and CG, 3th (Lengyel)
//    OpenGL Super Bible 6th (Sellers, Wright, Haemel)
//    OpenGL 4.0 Shading Cookbook (Wolff)

#version 330

in vec3 position;
in vec3 normal;

uniform mat4 modelView;
uniform mat3 normalMatrix;
uniform mat4 projection;
uniform vec4 lsPos;   //light source position in eye coord

out VS_OUT {
   vec3 vN;
   vec3 vL;
   vec3 vH;
} vsOut;

void main ()
{   
   vsOut.vN = normalize (normalMatrix*normal); // N - normal vector
   
   vec4 vPosition4 = (modelView)*vec4 (position, 1.0);   
   
   vsOut.vL = normalize (lsPos.xyz - vPosition4.xyz); // L - light vector   
   vec3 vV = normalize (-vPosition4.xyz); // V - viewer vector   
   vsOut.vH = normalize (vV + vsOut.vL); //HalfWay Vector -> Blinn-Phong Lighting
   
   gl_Position = projection*modelView*vec4 (position, 1.0);
}